<?php

namespace app\models;

use Yii;

/**
 * This is the model class for table "audio_label".
 *
 * @property integer $audio_id
 * @property integer $label_id
 * @property string $ctime
 *
 * @property Audio $audio
 * @property Label $label
 */
class AudioLabel extends \yii\db\ActiveRecord {
    /**
     * @inheritdoc
     */
    public static function tableName() {
        return 'audio_label';
    }

    /**
     * @inheritdoc
     */
    public function rules() {
        return [
            [['audio_id', 'label_id'], 'required'],
            [['audio_id', 'label_id'], 'integer'],
            [['ctime'], 'safe'],
            [['audio_id'], 'exist', 'skipOnError' => true, 'targetClass' => Audio::className(), 'targetAttribute' => ['audio_id' => 'id']],
            [['label_id'], 'exist', 'skipOnError' => true, 'targetClass' => Label::className(), 'targetAttribute' => ['label_id' => 'id']],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels() {
        return [
            'audio_id' => '音频id',
            'label_id' => '标签id',
            'ctime' => 'Ctime',
        ];
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getAudio() {
        return $this->hasOne(Audio::className(), ['id' => 'audio_id'])->inverseOf('audioLabels');
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getLabel() {
        return $this->hasOne(Label::className(), ['id' => 'label_id'])->inverseOf('audioLabels');
    }
}
